﻿using AutoMapper;
using BasicData.API.Read.Applications.Commands;
using BasicData.API.Read.Dtos;
using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infrastrueturc.Interfaces;
using MediatR;

namespace BasicData.API.Read.Applications.CommandHandlers
{
    public class SchoolQueryCommandHandler : IRequestHandler<SchoolQueryCommand, APIResult<List<ShowDTO>>>
    {
        private readonly IBaseReposiotry<School> schoolReposiorty;
        private readonly IMapper mapper;
        public SchoolQueryCommandHandler(IBaseReposiotry<School> schoolReposiorty, IMapper mapper)
        {
            this.schoolReposiorty = schoolReposiorty;
            this.mapper = mapper;
        }

        public Task<APIResult<List<ShowDTO>>> Handle(SchoolQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ShowDTO>> result=new APIResult<List<ShowDTO>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
           var list= schoolReposiorty.GetAll().ToList();
            var query=mapper.Map<List<ShowDTO>>(list);
            result.Data = query;
            return Task.FromResult(result);

        }
    }
}
